package cate.common.table.res.adventuretask;

import cate.common.table.ESheet;
import cate.common.util.random.RWList;
import cate.common.util.random.SimpleRwItem;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class AdventureTaskBaseSheet extends ESheet<AdventureTaskBaseRow>  {
    @Override
    public String getSheetName() {
        return "情报任务库";
    }

    public int randomTask(int group, Map<Integer, Integer> records, int openday){
        List<AdventureTaskBaseRow> rows = getList().stream().filter(e -> e.quality == group && openday >= e.opendayLimit).collect(Collectors.toList());
        if (rows.isEmpty()) {
            return 0;
        }
        RWList<SimpleRwItem> rwList = new RWList<>();
        for (AdventureTaskBaseRow weightRow : rows) {
            double weight = weightRow.getWeight();
            if (weightRow.maxRefreshTimes > 0 && records.getOrDefault(weightRow.id, 0) >= weightRow.maxRefreshTimes) {
                weight /= 2;
            }
            rwList.add(new SimpleRwItem(weightRow.id, weight));
        }
        return rwList.setup().get().getId();
    }
}
